//
//  HomeAPI.swift
//  LeGou
//
//  Created by lxm on 2022/7/27.
//
import Foundation

enum HomeAPI {
    // 淘宝搜索
    case tb_search(_ param : [String : Any])
    // 京东搜索
    case jd_search(_ param : [String : Any])
    // 拼多多搜索
    case pdd_search(_ param : [String : Any])
    // 第三方banner 列表
    case other_banner(_ param: String)
    // 淘宝分类
    case tb_goods_cate
    // 淘宝商品列表
    case tb_goods_list(_ param : [String : Any])
    // 淘宝商品详情
    case tb_goods_detail(_ goodsId : String)
    // 猜你喜欢
    case guess_like_list(_ param : [String : Any])
    // 淘宝签约备案
    case tb_userInfo(_ param : String)
    // 转链信息
    case tb_link_info(_ param : [String : Any])
    // 零元购口令
    case tb_newbuy_koiling(_ goodsId : String)
    // 首页京东
    case home_jd(_ param : [String : Any])
    // 首页拼多多
    case home_pdd(_ param : [String : Any])
    // 分红奖池
    case consumePool
    // 签到信息
    case signInInfo
    // 签到
    case signIn(_ param : [String : Any])
    // 查询签到订单支付状态
    case querySignPayResult(_ param : [String : Any])
    // banner
    case banner
    // 获取美团链接
    case mtLink(_ param : [String : Any])
    // 获取饿了么链接
    case elmLink(_ param : [String : Any])
    // 转链
    case change_link(_ param: String)
    // 弹窗公告banner
    case banner_pop(_ param : [String : Any])
    // 获取签到配置
    case signConfig
    // 抖音
    case douYin(_ param : [String : Any])
    // 连连
    case lianlian(_ param : [String : Any])
    
}

extension HomeAPI: ZMApiProvider {
    func BaseUrl() -> String {
        switch self {
            case .banner:
                return AppHelper.appVerify() ? DEV_BASE_URL : baseUrl
            default:
                break
        }
        return baseUrl
    }
    
    func urlAndMthodAndParam() -> (url: String, method: ZMHTTPMethod, params: [String : Any], body: Bool) {
        switch self {
        case .tb_search(let pa):
            return ("/api/front/tb/goods/search", .get, pa, false)
        case .jd_search(let pa):
            return ("/api/front/jd/search", .get, pa, false)
        case .pdd_search(let pa):
            return ("/api/front/pdd/goods/search", .get, pa, false)
        case .other_banner(let pa):
            return ("/api/front/banner/orderList", .get, ["type":pa], false)
        case .tb_goods_cate:
            return ("/api/front/tb/goods/getCid", .get, [:], false)
        case .tb_goods_list(let pa):
            return ("/api/front/tb/goods/hot", .get, pa, false)
        case .tb_goods_detail(let goodsId):
            return ("/api/front/tb/goods/detail/\(goodsId)", .get, [:], false)
        case .tb_userInfo(let pa):
            return ("/api/front/tb/userInfo", .get, ["sessionKey":pa], false)
        case .guess_like_list(let pa):
            return ("/api/front/tb/goods/listSimilarGoods/\(JSON(pa)["cid"].intValue)/\(JSON(pa)["goodsId"].intValue)", .get, pa, false)
        case .tb_link_info(let pa):
            return ("/api/front/tb/getPrivilegeLink", .post, pa, true)
        case .tb_newbuy_koiling(let pa):
            return ("/api/front/tb/getFirstPrivilegeLink", .get, ["goodsId":pa], false)
        case .home_jd(let pa):
            return ("/api/front/jd/jdHomePage", .get, pa, false)
        case .home_pdd(let pa):
            return ("/api/front/pdd/goods/homeProduct", .get, pa, false)
        case .consumePool:
            return ("/api/front/pool/bonusAmount", .get, [:], false)
        case .signInInfo:
            return ("/api/front/sign/getTaskData", .get, [:], false)
        case .signIn(let pa):
            return ("/api/front/sign/create", .post, pa, true)
        case .querySignPayResult(let pa):
            return ("/api/front/pay/querySignPayResult", .get, pa, false)
        case .banner:
            return ("/api/front/banner/list", .get, [:], false)
        case .mtLink(let pa):
            return ("/api/front/mt/getPromotionLink", .get, pa, false)
        case .elmLink(let pa):
            return ("/api/front/tb/hungryActivity", .post, pa, false)
        case .change_link(let pa):
            return ("/api/front/tb/getLink", .post, ["content":pa], false)
        case .banner_pop(let pa):
            return ("/api/front/banner/listNotice", .get, pa, false)
        case .signConfig:
            return ("/api/front/ahSign/getSignConfig", .get, [:], false)
        case .douYin(let pa):
            return ("/api/front/jvtuike/douyin/link", .get, pa, false)
        case .lianlian(let pa):
            return ("/api/front/jvtuike/lianliantravel/link", .get, pa, false)
        }
    }
    
    func HTTPHeader() -> ZMHTTPHeaders? {
        return AppHelper.reqeustHeader()
    }
    
    func UpLoadData() -> [Data]? {
        return nil
    }
    
    func ParamInBody() -> Bool {
        switch self {
//        case .tb_link_info:
//            return true
        default:
            return false
        }
    }
    
    func singleRequest() -> Bool {
        switch self {
            case .signInInfo:
                return true
            default:
                return false
        }
    }
}
